﻿<common:LayoutAwarePage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ShopPowerTemplate"
    xmlns:common="using:ShopPowerTemplate.Common"
    xmlns:controls="using:ShopPowerTemplate.Views"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:data="using:ShopPowerTemplate.Data"
    xmlns:MetroRate="using:MetroRate"
    xmlns:validation="using:ShopPowerTemplate.Common.Validation"
    x:Name="pageRoot"
    x:Class="ShopPowerTemplate.RatingViewPage"
    xmlns:Controls="using:Callisto.Controls"
    mc:Ignorable="d">

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="120"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!-- Horizontal scrolling grid used in most view states -->

        <Grid Grid.ColumnSpan="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyleCustom}" />
            <StackPanel x:Name="headerStackPanel" Grid.Column="1" Orientation="Horizontal">
                <Border x:Name="headerBorder" Height="80" Padding="0,0,20,0" Margin="0,0,20,0" BorderThickness="0,0,1,0" BorderBrush="{StaticResource ApplicationHeaderForegroundThemeBrush}">
                    <Image x:Name="headerImage" Source="ms-appx:///Assets/LogoShop.png" Stretch="Uniform" />
                </Border>
                <TextBlock x:Name="pageTitle" Text="{Binding Title}" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}" Margin="0" HorizontalAlignment="Left" VerticalAlignment="Center"/>
            </StackPanel>
            <controls:ShoppingCartButton x:Name="shoppingCartButton" Grid.Column="1" Margin="0,0,50,0" HorizontalAlignment="Right" VerticalAlignment="Center"/>
        </Grid>
        <StackPanel x:Name="reviewPanel" Grid.Column="1" Grid.Row="1">
            <StackPanel x:Name="starPanel" Orientation="Horizontal">
                <TextBlock x:Name="starTextBlock" Text="Tu valoración:" Style="{StaticResource SubheaderTextStyle}" />
                <Controls:Rating x:Name="StarRating" 
                                 Value="{Binding Review.Rating, Mode=TwoWay, Converter={StaticResource RatingMultiplierConverter}}" 
                                 IsEnabled="True" 
                                 ItemCount="5" 
                                 VerticalAlignment="Top" 
                                 Foreground="{StaticResource ApplicationHeaderForegroundThemeBrush}"
                                 PointerOverFill="{StaticResource ApplicationHeaderForegroundThemeBrush}"
                                 PointerPressedFill="{StaticResource ApplicationHeaderForegroundThemeBrush}"/>
            </StackPanel>
            <validation:RequiredTextValidationControl PropertyToValidate="{Binding ElementName=Review, Path=Text}" Style="{StaticResource ValidatorStyle}"/>
            <Controls:WatermarkTextBox x:Name="Review" 
                                       Watermark="Escriba su valoración..." 
                                       TextWrapping="Wrap" 
                                       Text="{Binding Review.Comment, Mode=TwoWay}" 
                                       HorizontalAlignment="Left" 
                                       VerticalAlignment="Top" 
                                       Height="226" 
                                       Width="513"/>
            <Button
                x:Name="addButton"
                Content="Añadir valoración" 
                Click="AddReview"
                Grid.Column="1" 
                HorizontalAlignment="Left" 
                Height="45" 
                Grid.Row="1" 
                VerticalAlignment="Top" 
                Width="174" />
        </StackPanel>

        <Border x:Name="bottomShoppingCartButton" Height="60" Grid.Row="2" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{StaticResource ApplicationHeaderForegroundThemeBrush}" Visibility="Collapsed">
            <controls:ShoppingCartButton x:Name="shoppingCartButton1" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{StaticResource ApplicationPageBackgroundThemeBrush}"/>
        </Border>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait" />

                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedButtonStyleCustom}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="shoppingCartButton">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="bottomShoppingCartButton">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.Column)" Storyboard.TargetName="headerStackPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.ColumnSpan)" Storyboard.TargetName="headerStackPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.Column)" Storyboard.TargetName="reviewPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.ColumnSpan)" Storyboard.TargetName="reviewPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="reviewPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="20"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Orientation" Storyboard.TargetName="starPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Vertical"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="StarRating">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="-3,0,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="HorizontalAlignment" Storyboard.TargetName="StarRating">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="HorizontalAlignment" Storyboard.TargetName="starTextBlock">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Width" Storyboard.TargetName="Review">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="275"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="HorizontalAlignment" Storyboard.TargetName="addButton">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)" Storyboard.TargetName="headerStackPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(StackPanel.Orientation)" Storyboard.TargetName="headerStackPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Vertical"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderThickness)" Storyboard.TargetName="headerBorder">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)" Storyboard.TargetName="headerBorder">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="headerBorder">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)" Storyboard.TargetName="pageTitle">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="pageTitle">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0,10"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Style)" Storyboard.TargetName="pageTitle">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedTitleTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="headerImage">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="40,20,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
